﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Import Namespace="PhotoGallery.Application" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	修改密码 - 重庆公安图片管理系统
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
	<div class="con-box">
		<div class="head">
			<h2>
				修改密码</h2>
		</div>
		  <%--<% PDCPMS.Model.Common.Account onlineAccount = PDCPMS.Application.UserSession.OnlineAccount; %>--%>
		<div class="con">            
			<div class="box">
				<% using (Html.BeginForm("Pwdedit", "Account", FormMethod.Post, new  {  id="mainForm"}))
       {%>
				<p><label class="i">
						登录名：</label>
						<%: Html.Encode(UserSession.OnlineAccount.LoginName)%>
				</p>
				<p>
					<label class="i" for="Password">
						旧密码：</label>
				   <input type="password" id="Password" name="Password" class="text w100"
						title="旧密码必填项，3到16个常用字符(a-z|A-Z|-_!@#$等)或者数字的组合，区分大小写" pattern="[\x21-\x7e]{3,16}" />
				</p>
				<p>
					<label class="i" for="newPassword" >
						新密码：</label>
					<input type="password" id="newPassword" name="NewPassword" class="text w100"
						title="新密码必填项，3到16个常用字符(a-z|A-Z|-_!@#$等)或者数字的组合，区分大小写" pattern="[\x21-\x7e]{3,16}" />
				</p>
				<p>
					<label class="i" for="PasswordConfirm">
						确认密码：</label>
					<input type="password" id="PasswordConfirm" name="PasswordConfirm" class="text w100"
						title="确认密码必填项，3到16个常用字符(a-z|A-Z|-_!@#$等)或者数字的组合，区分大小写" pattern="[\x21-\x7e]{3,16}" />
				</p>
				<div class="box">
					<span class="sexybutton" id="btn-submit"><span><span>
					<input type="submit" class="save" value="修改"/></span></span></span>
				</div>
				<% } %>
			</div>
		</div>
   </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="StyleContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ScriptContent" runat="server">
   <script type="text/javascript">
	   $(function () {
		   $("#mainForm input[type='text'],#mainForm input[type='password'],#mainForm textarea").tooltip({
			   position: "center right",
			   offset: [-2, 5],
			   effect: "fade",
			   opacity: 0.7
		   });
		   //$("#Birthday").dateinput({ selectors: true });
		   $("#mainForm").validator({ lang: 'zh-CN' });

		   $("#btn-submit").click(function () {
			   if (!CheckPassWord()) {
				   return false;
			   }

			   var oldPwd = $("#Password").val();
			   var newPwd = $("#newPassword").val();
			   var pageRedirectd = false;

			   try {
				   $.ajax({
					   url: '<%= Url.Action("UpdatePassword") %>',
					   type: 'POST',
					   data: {
						   loginName: '<%=PhotoGallery.Application.UserSession.OnlineAccount.LoginName %>',
						   oldPwd: oldPwd,
						   newPwd: newPwd
					   },
					   dataType: 'json',
					   success: function (data) {
						   if (data.success) {
							   cy.ui.showResult({ content: data.message, disappear: 5000 });
						   } else {
							   cy.ui.showResult({ content: data.message, disappear: 5000, className: 'cy-ui-results error' });
						   }
					   },
					   complete: function () {
						   if (!pageRedirectd)
							   $("#btn-submit").show();
					   }
				   });
			   } catch (e) {
				   window.console && console.log(e);
			   }
			   return false;
		   });


	   });
	</script>
	 <script type="text/javascript">
		 function CheckPassWord() {
			 var Password = $("#Password").val();
			 var newPassword = $("#newPassword").val();
			 var PasswordConfirm = $("#PasswordConfirm").val();

			 if (Password == null || Password.length < 3) {
				 alert("当前密码不能为空或当前密码长度不能少于3位!");
				 //$("#Password").submit();
				 return false;
			 }
			 if (newPassword == null || newPassword.length < 3) {
				 alert("新密码不能为空或当前密码长度不能少于3位!");
				 //$("#newPassword").submit();
				 return false;
			 }
			 if (PasswordConfirm == null || PasswordConfirm.length < 3) {
				 alert("确认密码不能为空或当前密码长度不能少于3位!");
				 //$("#PasswordConfirm").submit();
				 return false;
			 }
			 if (newPassword != PasswordConfirm) {
				 alert("新密码和确认密码不一致！请重新输入！")
				 return false;
			 }
			 return true;
		 }
	</script>
</asp:Content>
